
/*
 ============================================================================
 Name        : algoritmos_memoria.h
 Author      : mzavatto
 Version     :
 Copyright   :
 Description :
 ============================================================================
 */

#ifndef ALGORITMOS_MEMORIA_H_
#define ALGORITMOSMEMORIA_H_
#include <stdint.h>
#include <memcached/engine.h>
#include<time.h>

struct memory {
	rel_time_t exptime;
	int32_t flags;
	int32_t bsz; //bsz:tamaño de bloque
	char key[50]; //key: clave
	int32_t keysz; //keysz: tamaño de clave
	int32_t datasz; //datasz: tamaño del dato
	void* data; //key: puntero a la data
	int32_t stored; //si esta libre o no
	struct memory*link; //puntero al siguiente bloque
	time_t lastAccsess; //ultimo acceso al dato
};

void store(struct memory *current, struct memory *start,int32_t minBlock);
struct memory* find_prev(struct memory* current, struct memory *start);
struct memory* allocate(int32_t datasz, struct memory *start, int32_t criterio);
struct memory* best_fit(int32_t datasz, struct memory *start) ;
struct memory* first_fit(int32_t datasz, struct memory *start);
void compactar(struct memory *start);
void dealocate_item(char* clave, struct memory *start);
void dealocate_memory(int32_t criterio, struct memory *start);
struct memory* get_fifo(struct memory *start);
struct memory* get_lru(struct memory *start);
struct memory* get_value(char* clave,struct memory* start,int32_t criterio);
void flush(struct memory *start);
void show_mem_status(struct memory *start);

enum {
	FIFO = 0, LRU
};

enum {
	FIRST_FIT= 0, BEST_FIT, BUDDY_SYTEM
};



#endif /* ALGORITMOS_MEMORIA_H_ */
